home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus 1999 #1
/
Amiga Plus 1999 #1.iso
/
System-Boost
/
Workbench
/
BackClock
/
sources
/
obp.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-08-10
|
2KB
|
68 lines
/*****************************************************************************
*
* name : obp.c
* description : pens handling
* version : 1.1
*
* created : 13-03-98
* last change : 11-04-98
*
*****************************************************************************
*/
#include <intuition/intuition.h>
#include <intuition/screens.h>
#include <graphics/view.h>
#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/exec.h>
#include "obp.h"
#include "utils.h"
void setColors(idWin * prj) {
int i ;
prj->wb = LockPubScreen("Workbench") ;
for(i=0; i<NUM_COLORS; i++)
freePen(prj, prj->backWin.cmap[i].reg) ;
initColors(prj) ;
initwin(prj) ;
if (prj->wb) UnlockPubScreen(NULL, prj->wb) ;
prj->lastError = OK ;
}
void initColors(idWin * prj) {
int i ;
prj->wb = LockPubScreen("Workbench") ;
for(i=0; i<NUM_COLORS; i++) {
prj->backWin.cmap[i].reg = getPen(prj, prj->backWin.cmap[i].R,
prj->backWin.cmap[i].G,
prj->backWin.cmap[i].B) ;
}
if (prj->wb) UnlockPubScreen(NULL, prj->wb) ;
prj->lastError = OK ;
}
ULONG getPen(idWin * prj, UBYTE R, UBYTE G, UBYTE B) {
LONG color ;
struct Screen * wbscr ;
struct ColorMap * wbcm ;
if (wbscr = prj->wb) {
wbcm = wbscr->ViewPort.ColorMap ;
if ((color = ObtainBestPen(wbcm, ((LONG)R<<24)|0xffffff, ((LONG)G<<24)|0xffffff, ((LONG)B<<24)|0xffffff, TAG_DONE)) >=0 ) {
prj->lastError = OK ;
}else prj->lastError = ERRORNOMEM;
}
return((ULONG)color) ;
}
void freePen(idWin * prj, ULONG reg) {
struct Screen * wbscr ;
struct ColorMap * wbcm ;
if (wbscr = prj->wb) {
wbcm = wbscr->ViewPort.ColorMap ;
ReleasePen(wbcm, (LONG)reg) ;
}
}